/**
 * 
 */
package com.mc.yingshi;

import java.io.IOException;

import okhttp3.Call;
import okhttp3.FormBody;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.RequestBody;
import okhttp3.Response;

/**
 * 告警消息
 * @author w.weizhen
 *
 */
public class Alarm {
    private static String accessToken="at.bioki4eu2hbd93j5bx8ktplg8p1ez9eu-5fjkpdrtnf-0g0afip-gj4iwcmm7";
    private static String alarmList="https://open.ys7.com/api/lapp/alarm/list";//获取所有告警信息列表
    private static String alarmDeviceList="https://open.ys7.com/api/lapp/alarm/device/list";//按照设备获取告警消息列表
    /**
     * @param args
     */
    public static void main(String[] args) {
        //allList();
        
        deviceList();
    }
    
    //获取所有告警信息列表
    private static void allList(){
        OkHttpClient okHttpClient = new OkHttpClient();
        RequestBody requestBody = new FormBody.Builder()
            .add("accessToken", accessToken)//授权过程获取的access_token
            .add("startTime", "1649820951405")
            //.add("alarmType", "30010")//告警类型，默认为-1（全部）, 12086:移动侦测告警结束, 12116:网络断开, 12117:网络恢复, 10014:区域入侵,
            //.add("status", "2")//告警消息状态：2-所有，1-已读，0-未读，默认为0（未读状态）
            .add("pageStart", "0")//分页起始页，从0开始
            .add("pageSize", "50")//分页大小，默认为10，最大为,50
            .build();
        Request request = new Request.Builder()
            .url(alarmList)
            .post(requestBody)
            .build();
        Call call = okHttpClient.newCall(request);
        try {
            Response response = call.execute();
            String responseBody = response.body().string();
            System.out.println(responseBody);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
    
    //按照设备获取告警消息列表
    private static void deviceList(){
        OkHttpClient okHttpClient = new OkHttpClient();
        RequestBody requestBody = new FormBody.Builder()
            .add("accessToken", accessToken)//授权过程获取的access_token
            .add("deviceSerial", "D75675215")//设备序列号,存在英文字母的设备序列号，字母需为大写
            //.add("startTime", "1626278401000")//
            
            
//            .add("alarmType", "30010")//告警类型，默认为-1（全部）, 12086:移动侦测告警结束, 12116:网络断开, 12117:网络恢复, 10014:区域入侵,
//            .add("status", "2")//告警消息状态：2-所有，1-已读，0-未读，默认为0（未读状态）
//            .add("pageStart", "0")//分页起始页，从0开始
            //.add("pageSize", "50")//分页大小，默认为10，最大为,50
            .build();
        Request request = new Request.Builder()
            .url(alarmDeviceList)
            .post(requestBody)
            .build();
        Call call = okHttpClient.newCall(request);
        try {
            Response response = call.execute();
            String responseBody = response.body().string();
            System.out.println(responseBody);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
